//Townscript for town 8: Ruined castle

begintownscript;

variables;

int choice;

body;

beginstate INIT_STATE;

if (get_flag(8,6) == 1) {
		set_terrain(50,57,388);
		end();
		}
	set_terrain(50,57,384);

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
set_flag(275,5,8); // necessary for town 20 start_state
break;

beginstate 10;
if (get_flag(8,0) == 1)
		end();
	message_dialog("This old gatehouse is crumbling and could fall down any minute. As you look to the west and east wings of the castle, you see many holes in the once sturdy walls","");
	set_flag(8,0,1);
break;

beginstate 11;
if (get_flag(8,1) == 1)
		end();
	message_dialog("You stand in the big, once magnificent court yard. Now, the small pond has partly fell dry. You see a big hall to the south. You wonder what that magnificent big hall is.","");
	set_flag(8,1,1);
break;

beginstate 12;
if (get_flag(8,2) == 1)
		end();
	message_dialog("This big hall is the throne room. Big (now broken) statues stand along the wall. In the middle, on a heightening, two empty broken chairs stand. Everywhere you see holes in the walls.","");
	set_flag(8,2,1);
break;

beginstate 13;
	reset_dialog();
	add_dialog_str(0,"On this old pedestal lies a very old book. The pages are yellow and the water, slowly dripping from the ceiling, has made dark yellow circles on it. You could read the book. It looks pretty promising.",0);
	add_dialog_choice(0,"Leave the book alone.");
	add_dialog_choice(1,"Read it.");
	choice = run_dialog(0);
	
		if (choice == 2)
				set_state_continue(14);
break;

beginstate 14;
	reset_dialog();
	add_dialog_str(0,"You read this old book. It mainly contains the notes of the wizard who lived in this room. One thing is of interest though...",0);
	add_dialog_str(1,"_There is a big gate, crowded with monsters, through where the core is. To get through the gate, you will need a spell._ You repeat the spell several times, so you can memorise it.",0);
	add_dialog_str(2,"After knowing for sure you know the spell, you read what is written under the spell, in small, crude letters: _S.n..ti F..t!_ Its a pity that its not very readable. Anyhow, its a clue, but you wonder who wrote it.",0);
	add_dialog_choice(0,"Okay");
	choice = run_dialog(1);
	set_flag(8,10,1);
break;

beginstate 15;
if (get_flag(8,3) == 1)
		end();
	message_dialog("One thing that strikes you immediately when you enter the east side of the castle, is that it isn't as ruined as the west side.","The wizards who lived here used the projectors and beams as a sort of defence system.");
	set_flag(8,3,1);
break;

beginstate 16;
if (get_flag(8,4) == 0) {
		if (get_flag(8,6) == 0) {
				message_dialog("As you walk through this doorway, you immediately see the red projector beams. Before you can pass, you first have to get these beams off-line.","");
				set_flag(8,4,1);
				}
		}
break;

beginstate 17;
reset_dialog();
add_dialog_str(0,"Here stands an old, rusty lever. You probably could try to pull it.",0);
add_dialog_choice(0,"Leave.");
add_dialog_choice(1,"Pull.");
choice = run_dialog(1);
	
	if (choice == 2) {
			if (get_flag(8,5) == 0) {
					message_dialog("All you hear is a very satisfied _clunk_ sort of noise. Nothing else happens. It is probably broken","");
					swap_terrain(54,26,375,374);
					run_animation_sound(106);
					set_flag(8,5,1);
					end();
					}
				
			if (get_flag(8,5) == 1) {
					message_dialog("All you hear is a very satisfied _clunk_ sort of noise. Nothing else happens. It is probably broken","");
					swap_terrain(54,26,374,375);
					run_animation_sound(106);
					set_flag(8,5,0);
					end();
					}
			}
break;

beginstate 18;
	move_to_new_town(9,6,20);
break;

beginstate 19;
if (get_flag(8,6) == 1) {
		set_terrain(50,57,388);
		end();
		}
	set_terrain(50,57,384);
break;

beginstate 20;
if (get_flag(8,7) == 1)
		end();
	message_dialog("This is a quite peculiar room. You see a beautiful paved floor, and some mosaic floors. But on the mosaic floors stand some cooking pots.","It was probably used by the wizards as some potion demonstration hall.");
	set_flag(8,7,1);
break;

beginstate 21;
if (get_flag(8,8) != 0)
		end();
	message_dialog("The pedestal is crumbling and the book that lies on it also isn't in a really good state. Its a pity that its not very readable anymore.","There is one word though, that looks quite readable. It says _Empire rec..ds 1 unt.l 3._  Pity that some letters are not readable anymore.");
	set_flag(8,8,1);
break;

beginstate 22;
	change_outdoor_location(4,1,41,22);
	move_to_new_town(20,9,58);
break;